from flask import Flask, jsonify, request, Blueprint
app = Flask(__name__)
announcement_bp = Blueprint('announcement', __name__)

@announcement_bp.route('/api/announcements', methods=['GET'])
def get_announcements_by_query():
    from service.AnnouncementService import get_announcements_by_query
    page_num = request.args.get('page_num', 1, type=int)
    page_size = request.args.get('page_size', 10, type=int)
    type = request.args.get('type',None)
    title_keyword = request.args.get('title_keyword',None)
    content_keyword = request.args.get('content_keyword',None)
    start_date = request.args.get('start_date',None)
    end_date = request.args.get('end_date',None)
    result = get_announcements_by_query(page_num,page_size,type,title_keyword,content_keyword,start_date,end_date)
    print(result)
    return jsonify(result)


@announcement_bp.route('/api/announcements/<announcement_id>', methods=['GET'])
def get_announcement(announcement_id):
    from service.AnnouncementService import get_announcement
    result = get_announcement(announcement_id)
    print(result)
    return jsonify(result)

@announcement_bp.route('/api/announcements', methods=['POST'])
def create_announcement():
    from service.AnnouncementService import create_announcement
    result = create_announcement()
    print(result)
    return jsonify(result)



@announcement_bp.route('/api/announcements/<announcement_id>', methods=['PUT'])
def update_announcement(announcement_id):
    from service.AnnouncementService import update_announcement
    result = update_announcement(announcement_id)
    print(result)
    return jsonify(result)

@announcement_bp.route('/api/announcements/<announcement_id>', methods=["DELETE"])
def delete_announcement(announcement_id):
    from service.AnnouncementService import delete_announcement
    result = delete_announcement(announcement_id)
    print(result)
    return jsonify(result)